//
//  JZAppDelegate.m
//  JZAdSDK
//
//  Created by 二跳 on 09/28/2025.
//  Copyright (c) 2025 二跳. All rights reserved.
//

#import "JZAppDelegate.h"
#import <JZAdSDK/JZAdSDK.h>
#import <JZAdSDK/JZAdSDKSplashAd.h>

@interface JZAppDelegate ()<JZAdSDKSplashAdDelegate>

@property (nonatomic, strong) JZAdSDKSplashAd *splashAd;

@end

@implementation JZAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    
    [JZAdSDK initWithAppId:@"444444" requestDomain:@"" completionBlock:^(NSError * _Nullable error) {
        if (error) {
            NSLog(@"初始化jz SDK失败：%@", error.localizedDescription);
        } else {
            NSLog(@"初始化jz SDK成功");
            // [self loadSplashAd];
        }
    }];
    
    [self loadSplashAd];
    // Override point for customization after application launch.
    return YES;
}

- (void)loadSplashAd{
    self.splashAd = [[JZAdSDKSplashAd alloc]init];
    self.splashAd.posId = @"59052052";
    self.splashAd.delegate = self;
    self.splashAd.controller = self.window.rootViewController;
//    self.splashAd.skipButtonToRightTop = false;
    [self.splashAd loadSplashAd];
    
}

#pragma mark - JZAdSDKSplashAdDelegate
/**
 开屏广告点击回调, 可能会打开 AppStore, WebView, ThirdApp etc.

 @param splashAd 开屏广告
 */
- (void)JZ_splashAdDidClick:(JZAdSDKSplashAd *)splashAd{
    NSLog(@"%s", __func__);
}

/**
 开屏广告关闭回调, 触发条件: 点击广告, 点击跳过, 超时关闭

 @param splashAd 开屏对象
 */
- (void)JZ_splashAdDidClose:(JZAdSDKSplashAd *)splashAd{
    NSLog(@"%s", __func__);
    self.splashAd = nil;
}

/**
 开屏广告展示回调

 @param splashAd 开屏对象
 */
- (void)JZ_splashAdExposured:(JZAdSDKSplashAd *)splashAd{
    NSLog(@"%s", __func__);
}

/**
 开屏广告加载成功
 
 @param splashAd 开屏对象
 */
- (void)JZ_splashAdDidLoad:(JZAdSDKSplashAd *)splashAd{
    NSLog(@"%s", __func__);
    [self.splashAd showSplashAdInWindow:self.window];
    NSInteger price = [self.splashAd getBidPrice];
    [self.splashAd sendWinNotice:price];
}

/**
 开屏广告加载失败
 
 @param splashAd 开屏对象
 */
- (void)JZ_splashAdDidFailToLoad:(JZAdSDKSplashAd *)splashAd error:(NSError *)error{
    NSLog(@"%s, err:%@", __func__, error.localizedDescription);
    self.splashAd = nil;
}

/**
 *  开屏广告成功展示
 *
 *  @param splashAd 开屏对象
 */
- (void)JZ_splashAdSuccessPresentScreen:(JZAdSDKSplashAd *)splashAd{
    NSLog(@"%s", __func__);
}

/**
 *  开屏广告展示失败
 *
 *  @param splashAd 开屏对象
 */
- (void)JZ_splashAdFailToPresent:(JZAdSDKSplashAd *)splashAd withError:(NSError *)error{
    NSLog(@"%s", __func__);
    self.splashAd = nil;
}

/**
 *  开屏广告关闭落地页
 *
 *  @param splashAd 开屏对象
 */
- (void)JZ_splashAdCloseLandingPage:(JZAdSDKSplashAd *)splashAd{
    NSLog(@"%s", __func__);
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
